package io.itit.ecp.admin.common.enums;

import io.itit.grass.common.enums.IBaseEnum;
import io.itit.grass.common.exception.GrassException;

import java.io.Serializable;

public enum StatisticsModeEnums implements IBaseEnum {

    hour("hour", "%Y/%m/%d %H时", "yyyy/MM/dd HH时", "时"),
    day("day", "%Y/%m/%d", "yyyy/MM/dd", "天"),
    month("month", "%Y/%m", "yyyy/MM", "月"),
    year("year", "%Y", "yyyy", "年");

    public final String mode;
    public final String mysqlDateFormat;
    public final String javaDateFormat;
    public final String desc;

    StatisticsModeEnums(String mode, String mysqlDateFormat, String javaDateFormat, String desc) {
        this.mode = mode;
        this.mysqlDateFormat = mysqlDateFormat;
        this.javaDateFormat = javaDateFormat;
        this.desc = desc;
    }

    public static String mysqlDateFormat(String mode) {
        for (StatisticsModeEnums enums : StatisticsModeEnums.values()) {
            if (enums.mode.equals(mode)) {
                return enums.mysqlDateFormat;
            }
        }
        throw new GrassException("【" + mode + "】未匹配到MySQL日期格式化方式！");
    }

    public static String mysqlDateFormatVis(String mode) {
        if (StatisticsModeEnums.hour.mode.equals(mode)) {
            return "%m/%d %H:00";
        }
        return mysqlDateFormat(mode);
    }

    public static String javaDateFormat(String mode) {
        for (StatisticsModeEnums enums : StatisticsModeEnums.values()) {
            if (enums.mode.equals(mode)) {
                return enums.javaDateFormat;
            }
        }
        throw new GrassException("【" + mode + "】未匹配到Java日期格式化方式！");
    }

    @Override
    public Serializable getValue() {
        return mode;
    }

    @Override
    public String getDesc() {
        return desc;
    }
}

